const { 
  listBuckets, 
  listObjects, 
  generatePresignedUrl, 
  uploadFile, 
  deleteFile, 
  syncFolder, 
  createBucket, 
  deleteBucket, 
  deleteFolder 
} = require('./r2Operations');

// 使用示例
async function runExample() {
  try {
    // 列出所有bucket
    const buckets = await listBuckets();
    if (buckets.length === 0) {
      console.log('No buckets found.');
      // 创建新桶示例
      // await createBucket('my-new-bucket');
      return;
    }

    // 选择第一个bucket
    const firstBucket = buckets[0].Name;
    console.log(`Using bucket: ${firstBucket}`);

    // 列出bucket中的对象
    // await listObjects(firstBucket);

    // 生成一个预签名URL
    // await generatePresignedUrl(firstBucket, 'dog.png');

    // 上传文件示例
    // await uploadFile(firstBucket, './test.png');

    // 删除文件示例
    // await deleteFile(firstBucket, 'test.png');

    await deleteFolder(firstBucket, 'share/client/v1');
    // 同步文件夹示例
    await syncFolder(firstBucket, 'K:\\my-space\\node-docker\\client\\dist', 'share/client/v1');

    // 删除文件夹示例
    // await deleteFolder(firstBucket, 'one/share/client/v1');

    // 创建新桶示例
    // await createBucket('my-second-bucket2');

    // 删除桶示例
    // await deleteBucket('my-second-bucket');
    // await deleteBucket('my-second-bucket2');

  } catch (error) {
    console.error('Error in example:', error);
  }
}

runExample();